package com.site.web.controller.war;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.site.common.annotation.Log;
import com.site.common.core.controller.BaseController;
import com.site.common.core.domain.AjaxResult;
import com.site.common.enums.BusinessType;
import com.site.war.domain.SiteWarningMessage;
import com.site.war.service.ISiteWarningMessageService;
import com.site.common.utils.poi.ExcelUtil;
import com.site.common.core.page.TableDataInfo;

/**
 * 预警信息Controller
 * 
 * @author site
 * @date 2023-10-10
 */
@RestController
@RequestMapping("/war/message")
public class SiteWarningMessageController extends BaseController
{
    @Autowired
    private ISiteWarningMessageService siteWarningMessageService;

    /**
     * 查询预警信息列表
     */
    @PreAuthorize("@ss.hasPermi('site:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(SiteWarningMessage siteWarningMessage)
    {
        startPage();
        List<SiteWarningMessage> list = siteWarningMessageService.selectSiteWarningMessageList(siteWarningMessage);
        return getDataTable(list);
    }

    /**
     * 导出预警信息列表
     */
    @PreAuthorize("@ss.hasPermi('site:message:export')")
    @Log(title = "预警信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SiteWarningMessage siteWarningMessage)
    {
        List<SiteWarningMessage> list = siteWarningMessageService.selectSiteWarningMessageList(siteWarningMessage);
        ExcelUtil<SiteWarningMessage> util = new ExcelUtil<SiteWarningMessage>(SiteWarningMessage.class);
        util.exportExcel(response, list, "预警信息数据");
    }

    /**
     * 获取预警信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('site:message:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(siteWarningMessageService.selectSiteWarningMessageById(id));
    }

    /**
     * 新增预警信息
     */
    @PreAuthorize("@ss.hasPermi('site:message:add')")
    @Log(title = "预警信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SiteWarningMessage siteWarningMessage)
    {
        return toAjax(siteWarningMessageService.insertSiteWarningMessage(siteWarningMessage));
    }

    /**
     * 修改预警信息
     */
    @PreAuthorize("@ss.hasPermi('site:message:edit')")
    @Log(title = "预警信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SiteWarningMessage siteWarningMessage)
    {
        return toAjax(siteWarningMessageService.updateSiteWarningMessage(siteWarningMessage));
    }

    /**
     * 删除预警信息
     */
    @PreAuthorize("@ss.hasPermi('site:message:remove')")
    @Log(title = "预警信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(siteWarningMessageService.deleteSiteWarningMessageByIds(ids));
    }
}
